package com.luodeng.luodengprometheusdemo;

import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;

@SpringBootApplication
public class LuodengPrometheusDemoApplication {

	private static Logger logger= LoggerFactory.getLogger(LuodengPrometheusDemoApplication.class);

	public static void main(String[] args) {
		SpringApplication app= new SpringApplication(LuodengPrometheusDemoApplication.class);
		Environment env = app.run(args).getEnvironment();
		try {
			logger.info("\n----------------------------------------------------------\n\t" +
							"Application '{}' is running! Access URLs:\n\t" +
							"Local: \t\thttp://localhost:{}\n\t" +
							"External: \thttp://{}:{}\n\t" +
							"SwaggerUI: \thttp://localhost:{}/doc.html\n" +
							"actuator: \thttp://localhost:{}/actuator\n" +
							"----------------------------------------------------------",
					env.getProperty("spring.application.name"),
					env.getProperty("server.port"),
					InetAddress.getLocalHost().getHostAddress(),
					env.getProperty("server.port"),
					env.getProperty("server.port"),
					env.getProperty("server.port"));
		} catch (UnknownHostException e) {
			logger.error(e.getMessage(),e);
		}

	}


	@Bean
	MeterRegistryCustomizer<MeterRegistry> configurer(@Value("${spring.application.name}") String applicationName) {
		return (registry) -> registry.config().commonTags("application", applicationName);
	}

}
